package com.work.demo.sched;

import com.work.demo.service.ImsvaluesService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * 国网三期运行监控
 *
 * @author linya
 */
@Slf4j
@Component
public class GridOperationMonitorScheduler {

    @Autowired
    private ImsvaluesService imsvaluesService;

    @Value("${grid.corporation.code:10}")
    private String corporationCode;

    @Value("${spring.datasource.url:}")
    private String datasourceUrl;

    /**
     * 系统服务响应时长
     */
    @Scheduled(fixedRate = 1, timeUnit = TimeUnit.MINUTES)
    public void saveSysResponseTime() throws InterruptedException {
    }


    /**
     * 系统健康运行时长
     */
    @Scheduled(initialDelay = 5, fixedRate = 5, timeUnit = TimeUnit.MINUTES)
    public void saveSysRunningTime() {

    }

    /**
     * 业务应用系统占用表空间大小
     */
    @Scheduled(initialDelay = 1, fixedRate = 1, timeUnit = TimeUnit.DAYS)
    public void saveSysDataTableSpace() {

    }

    /**
     * 数据库平均响应时长
     */
    @Scheduled(initialDelay = 5, fixedRate = 5, timeUnit = TimeUnit.MINUTES)
    public void saveSysDBTime() {

    }

    private String extractDbName() {
        String dbName = null;
        if (StringUtils.isNotBlank(datasourceUrl)) {
            String address = datasourceUrl.substring(0, datasourceUrl.indexOf("?"));
            dbName = address.substring(address.lastIndexOf("/") + 1);
        }
        return dbName;
    }
}
